package com.ellricky.baselib.ui.task.beike;


import android.view.View;
import android.widget.AdapterView;

import com.andr.common.http.callback.BaseCallback;
import com.andr.common.ui.adapter.BaseRecyclerAdapter;
import com.andr.common.ui.mvp.BasePresenter;
import com.andr.common.util.StrUtil;
import com.andr.common.widget.refresh.RefreshFlag;
import com.ellricky.baselib.R;
import com.ellricky.baselib.adapter.task.PreLessonAdapter;
import com.ellricky.baselib.entity.task.PreLessonEntity;
import com.ellricky.baselib.http.callback.EListCallback;
import com.ellricky.baselib.ui.base.BaseRefreshActivity;
import com.ellricky.baselib.util.EAppUtil;


import java.util.List;

import static com.ellricky.baselib.http.Api.API_PRE_LESSON_LIST;

public class PreLessonActivity extends BaseRefreshActivity<Void, BasePresenter<Void>, PreLessonEntity> {

    @Override
    public void initUIView() {
        super.initUIView();
        mTvTitle.setText(R.string.base_pre_lesson_task);
    }

    @Override
    protected void setRefreshListener() {
        rvView.init(this, RefreshFlag.REFRESH);
    }

    @Override
    protected BaseCallback getResponseCallback() {
        return new EListCallback<PreLessonEntity>(this) {
            @Override
            protected void onSuccess(List<PreLessonEntity> data, String msg) {
                dataSource = data;
                rvView.onLoadFinish(dataSource, refresh);
            }

            @Override
            protected void onErrorCode(String code, String msg) {
                super.onErrorCode(code, msg);
                rvView.onRefreshFailed(refresh);
            }

            @Override
            protected void onHttpError(String code, String msg) {
                super.onHttpError(code, msg);
                rvView.onRefreshFailed(refresh);
            }
        };
    }

    @Override
    protected BaseRecyclerAdapter<PreLessonEntity> getRvAdapter() {
        return new PreLessonAdapter();
    }


    @Override
    protected String getUrlPath() {
        return API_PRE_LESSON_LIST;
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
        super.onItemClick(adapterView, view, position, l);
        PreLessonEntity entity = adapter.get(position);
        if (StrUtil.isEquals("0", entity.getPreStatus())) {
            // todo 未备课
            EAppUtil.jumpPageWithId(this, PreLessonSaveActivity.class, entity.getId());
        } else {
            // 已备课
            EAppUtil.jumpPageWithId(this, PreLessonDetailActivity.class, entity.getPreId());
        }
    }

}
